﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsGameLibrary1;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Bipoland
{
    public class Ratita:Entity
    {
        private AnimationPlayer animationPlayer;
        private Vector2 position;        
        private float speed;
        private int direction;
        private Shift shift;

             

        public Ratita(Shift shift) 
        {
            animationPlayer = new AnimationPlayer();
            position = new Vector2();
            speed = 25;
            direction = 1;
            this.shift = shift;            
            if (shift.Equals(Shift.White))
            {
                animationPlayer.ColorFunction = White;
            }
            else
            {
                animationPlayer.ColorFunction = Black;
            }
            
        }

        public Vector2 Position1
        {
            get { return position; }
            set { position = value; }
        }

        #region Entity Members
        
        public void LoadContent(ContentManager Content)
        {
            Frame ratita = new Frame();
            ratita.Duration = 0.2f;
            ratita.Origin = Vector2.Zero;
            ratita.FlipOrigin = Vector2.Zero;
            ratita.Sprite = Content.Load<Texture2D>("Ratita/Ratita");

            Animation rat = new Animation();
            rat.AnimationTime = 0.2f;
            rat.SpriteCount = 1;
            rat.AddFrame(ratita);

            animationPlayer.AddAnimation(AnimationPlayerEnum.CAMINANDO,rat);
            animationPlayer.ChangeAnimation(AnimationPlayerEnum.CAMINANDO, ModeEnum.Ever);
            animationPlayer.Play();

            
        }

        public void Update(GameTime gameTime)
        {
            if (position.X + gameTime.ElapsedGameTime.TotalSeconds*speed*direction < 800 && direction==1)
            {
                position.X += (float)gameTime.ElapsedGameTime.TotalSeconds * speed * direction;
                animationPlayer.SpriteEffects = SpriteEffects.None;
            }
            else
            {
                direction=-1;
                
                if (position.X + gameTime.ElapsedGameTime.TotalSeconds * speed * direction > 100)
                {
                    position.X += (float) gameTime.ElapsedGameTime.TotalSeconds * speed * direction;
                    animationPlayer.SpriteEffects = SpriteEffects.FlipHorizontally;
                }
                else
                {
                    direction = 1;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime, float order, float scroller)
        {
            animationPlayer.Draw(spriteBatch, gameTime, new Vector2(position.X - scroller, position.Y), 0);
        }

        public Vector2 Position()
        {
            throw new NotImplementedException();
        }

        public Vector2 ImageSize()
        {
            throw new NotImplementedException();
        }

        public void CollisionAction(Entity entity)
        {
            throw new NotImplementedException();
        }

        public BoundingBox CollisionRectangle()
        {
            throw new NotImplementedException();
        }

        public List<CollisionCoordinates> CollisionRectangles()
        {
            throw new NotImplementedException();
        }

        public float GivePaintOrder()
        {
            throw new NotImplementedException();
        }

        public bool isdying()
        {
            throw new NotImplementedException();
        }
        
        #endregion
        public Color Black(Color color,GameTime gametime)
        {
            color = Color.Black;
            return color;
        }

        public Color White(Color color, GameTime gametime)
        {
            color = Color.White;
            return color;
        }

        public Color Gray(Color color, GameTime gametime)
        {
            color = Color.Gray;
            return color;
        }

        public ColorFunction changeColor() 
        {
            
            if (shift.Equals(Shift.White))
            {
                 return White;
            }
            else
            {
                return Black;
            }

        }
    }
}
